from datetime import datetime
from src.models.models import db, get_beijing_time

class SoftwareLicense(db.Model):
    __tablename__ = 'software_license'
    id = db.Column(db.Integer, primary_key=True)
    serial = db.Column(db.String(64), unique=True, nullable=False)
    created_at = db.Column(db.DateTime, default=get_beijing_time)
    remark = db.Column(db.String(128), default='')

    @staticmethod
    def get_license():
        return SoftwareLicense.query.first()

    @staticmethod
    def create_license(serial, remark=''):
        license = SoftwareLicense(serial=serial, remark=remark)  # type: ignore
        db.session.add(license)
        db.session.commit()
        return license 